package cz.cvut.fel.gfupan.gui.util;

import java.util.ArrayList;
import java.util.List;

public class AutoCompleteList {
    public static final int OVERVIEW_MEASURE = 7;

    public static List<AutoCompleteItem> getList() {
        List<AutoCompleteItem> list = new ArrayList<AutoCompleteItem>();
        fillList(list);

        return list;
    }

    private static void fillList(List<AutoCompleteItem> list) {
        for (int measure = 1; measure < 7; ++measure) {
            addMeasure(measure, list);
        }
        list.add(new AutoCompleteItem(OVERVIEW_MEASURE, 0, 0, getFromBundle("Window", "overviewButton.text")));

    }

    //humus :D
    private static void addMeasure(int measure, List<AutoCompleteItem> list) {
        list.add(makeItem(measure, 1, 1, "headerDate.text"));
        list.add(makeItem(measure, 1, 2, "headerAuthor.text"));
        list.add(makeItem(measure, 1, 3, "headerDevice.text"));
        list.add(makeItem(measure, 1, 4, "headerTemp.text"));
        list.add(makeItem(measure, 1, 5, "headerPlace.text"));
        list.add(makeItem(measure, 1, 6, "headerNote.text"));

        list.add(makeItem(measure, 2, 1, "mireAzimut.text"));
        list.add(makeItem(measure, 2, 2, "mireMeasure1.text"));
        list.add(makeItem(measure, 2, 3, "mireMeasure2.text"));
        list.add(makeItem(measure, 2, 4, "mireMeasure3.text"));
        list.add(makeItem(measure, 2, 5, "mireMeasure4.text"));
        list.add(makeItem(measure, 2, 6, "mireError.text"));

        list.add(makeItem(measure, 3, 1, "declinationMeasure1.text"));
        list.add(makeItem(measure, 3, 2, "declinationMeasure2.text"));
        list.add(makeItem(measure, 3, 3, "declinationMeasure3.text"));
        list.add(makeItem(measure, 3, 4, "declinationMeasure4.text"));
        list.add(makeItem(measure, 3, 5, "declinationAvgDeclination.text"));
        list.add(makeItem(measure, 3, 6, "declinationMeridian.text"));
        list.add(makeItem(measure, 3, 7, "declinationAvgTime.text"));

        list.add(makeItem(measure, 4, 1, "inclinationMeasure1.text"));
        list.add(makeItem(measure, 4, 2, "inclinationMeasure2.text"));
        list.add(makeItem(measure, 4, 3, "inclinationMeasure3.text"));
        list.add(makeItem(measure, 4, 4, "inclinationMeasure4.text"));
        list.add(makeItem(measure, 4, 5, "inclinationAvgInclination.text"));

        list.add(makeItem(measure, 5, 1, "totalMeasure1.text"));
        list.add(makeItem(measure, 5, 2, "totalMeasure2.text"));
        list.add(makeItem(measure, 5, 3, "totalMeasure3.text"));
        list.add(makeItem(measure, 5, 4, "totalMeasure4.text"));
        list.add(makeItem(measure, 5, 5, "totalMeasure5.text"));
        list.add(makeItem(measure, 5, 6, "totalMeasure6.text"));
        list.add(makeItem(measure, 5, 7, "totalMeasure7.text"));
        list.add(makeItem(measure, 5, 8, "totalMeasure8.text"));
        list.add(makeItem(measure, 5, 9, "totalMeasure9.text"));
        list.add(makeItem(measure, 5, 10, "totalMeasure10.text"));
        list.add(makeItem(measure, 5, 11, "totalMeasure11.text"));
        list.add(makeItem(measure, 5, 12, "totalMeasure12.text"));
        list.add(makeItem(measure, 5, 13, "totalAvgError.text"));
    }

    private static AutoCompleteItem makeItem(int measure, int tab, int id, String name) {
        return new AutoCompleteItem(measure, tab, id, "" + measure + " " + bundle(name));
    }

    private static String bundle(String name) {
        return getFromBundle("MeasurePanel", name);
    }

    private static String getFromBundle(String componentName, String name) {
        return Bundle.get(componentName, name).replaceAll(":", "");
    }

    public static AutoCompleteItem find(AutoCompleteItem sample, List<AutoCompleteItem> all) {
        for (AutoCompleteItem one : all) {
            if (one.equals(sample)) {
                return one;
            }
        }
        return null;
    }
}
